package com.sjc.consumer.service.impl;

import com.sjc.consumer.service.ITransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("transferServiceConfirm")
public class TransferServiceConfirm implements ITransferService {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Transactional
    @Override
    public void transfer(String sourceAcctId, String targetAcctId, double amount) {
        System.out.printf("confirm : acct= %s, amount= %7.2f%n", sourceAcctId, amount);
        int value = this.jdbcTemplate.update("update tb_account_two set frozen = frozen - ? where acct_id = ?", amount, sourceAcctId);
        if (value != 1) {
            throw new IllegalStateException("ERROR!");
        }
    }
}
